<?php
/**
 * School form
 *
 * @version $Id: Base.php 73 2010-04-25 00:30:44Z yingkuang.chen@gmail.com $
 * @license New BSD License
 * @uses Zend_Form
 * @package school
 * @subpackage Form
 */
class School_Form_Base extends Sfs_Form
{
	protected $_formState;

	protected $_school;

	public function __construct($formState='')
	{
		$this->_formState = $formState;
		$this->_school = new School_Model_School();

		parent::__construct();
	}

	private function _setValue()
	{
	//	$q = Doctrine_Query::create()
	//	->setHydrationMode(Doctrine::HYDRATE_ARRAY)
    //->from('School_Model_School');
	//	$data =$q->fetchOne();
		//$school = new School_Model_DbTable_School();
		//$data = $school->fetchAll()->current()->toArray();
        $data = Doctrine::getTable('School_Model_School')->findAll()->getFirst()->toArray();
		$this->setDefaults($data);
		$this->setDefault('show_id',$data['id']);
	}

	/**
	 * initialization routine
	 *
	 * @return void
	 */
	public function init()
	{

		$this->setMethod('post');
		$this->addElement('hidden', 'id', array(
			'decorators' => $this->noElementDecorator,
        	'required'   => true,
        	'filters'    => array('StringTrim'),
			'validators' => array()
		)
		);

		$this->addElement('text', 'show_id', array(
			'label'      => 'id',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'commercial_id', array(
		//   'decorators' => $this->_standardElementDecorator,
        	'label'      => 'commercial_id',
        	'required'   => true,
        	'filters'    => array('StringTrim'),

		//	'validators' => array()
		)
		);
		$this->addElement('text', 'governmental_id', array(
		//    'decorators' => $this->_standardElementDecorator,
        	'label'      => 'governmental_id',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()getAttributeArr
		)
		);

		$this->addElement('select', 'attribute', array(
        	'label'      => 'attribute',

		//     'decorators' => $this->_standardElementDecorator,
        	'required'   => true,
        	'filters'    => array('StringTrim'),
			'multiOptions' => $this->_school->getAttributeArr(),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'name', array(
        	'label'      => 'school_name',
		//     'decorators' => $this->_standardElementDecorator,
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);

		$this->addElement('text', 'name_short', array(
        	'label'      => 'name_short',
		//	 'decorators' => $this->_standardElementDecorator,
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'name_brief', array(
        	'label'      => 'name_brief',
		//	 'decorators' => $this->_standardElementDecorator,
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'english_name', array(
        	'label'      => 'english_name',
		//	 'decorators' => $this->_standardElementDecorator,
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('select', 'length', array(
        	'label'      => 'length',
		//	 'decorators' => $this->_standardElementDecorator,
        	'required'   => true,
		  'multiOptions' => $this->_school->getAttrArr(),
		//'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'length_name', array(
        	'label'      => 'length_name',
		//	 'decorators' => 0.00$this->_standardElementDecorator,
      //  	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('select', 'county', array(
        	'label'      => 'county',
        	'required'   => true,
		 	'multiOptions'=>$this->_school->getCountyArr()
		//'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);


		$this->addElement('text', 'form_date', array(
        	'label'      => 'form_date',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
			'validators' => array('date')
		)
		);
		$this->addElement('select', 'mark', array(
        	'label'      => 'mark',
        	'required'   => true,
        	//'filters'    => array('StringTrim'),
        	'multiOptions'=>$this->_school->getMarkArr()
		//	'validators' => array()
		)
		);
		$this->addElement('select', 'area', array(
        	'label'      => 'area',
        	'required'   => true,
        	'multiOptions'=>$this->_school->getAreaArr()
		//	'validators' => array()
		)
		);
		$this->addElement('select', 'montane', array(
        	'label'      => 'montane',

        	'multiOPtions'=>$this->_school->getYesNoArr()
		)
		);
		$this->addElement('text', 'plottage', array(
        	'label'      => 'plottage',
        	'filters'    => array('StringTrim'),
			'validators' => array('float')
		)
		);
		$this->addElement('text', 'plottage_expand', array(
        	'label'      => 'plottage_expand',
        	'filters'    => array('StringTrim'),
			'validators' => array('float')
		)
		);
		$this->addElement('text', 'floor_space', array(
        	'label'      => 'floor_space',
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'expense_capital', array(
        	'label'      => 'expense_capital',
        	'filters'    => array('StringTrim'),
			'validators' => array('float')
		)
		);
		$this->addElement('text', 'expense_ordinary', array(
        	'label'      => 'expense_ordinary',
			'validators' => array('float')
		)
		);
		$this->addElement('text', 'township', array(
        	'label'      => 'township',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'zip_code', array(
        	'label'      => 'zip_code',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'address', array(
        	'label'      => 'address',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'phone', array(
        	'label'      => 'phone',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'fax', array(
        	'label'      => 'fax',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'district', array(
        	'label'      => 'district',
       // 	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'scale', array(
        	'label'      => 'scale',
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'email', array(
        	'label'      => 'email',
      //  	'required'   => true,
        	'filters'    => array('StringTrim'),
			'validators' => array('EmailAddress')
		)
		);
		$this->addElement('text', 'website', array(
        	'label'      => 'website',
     //   	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);

		$this->addElement('text', 'memo', array(
        	'label'      => 'memo',
        	//'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);

		$this->addElement('text', 'update_sn', array(
        	'label'      => 'update_sn',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);
		$this->addElement('text', 'update_ip', array(
        	'label'      => 'update_ip',
        	'required'   => true,
        	'filters'    => array('StringTrim'),
		//	'validators' => array()
		)
		);

		$this->addElement('submit','submit',array(
			'label'=> 'save'
		));

		$logo_picture_img = $this->createElement('file', 'logo_picture_img', array(
        	'label'      => 'logo_picture',
        	'filters'    => array('StringTrim'),
		)
		);

		$logo_picture_img->addValidator('Count', true, 2)
		 ->addValidator('Size', true, "3000KB")
       ->addValidator('Extension', true, array('jpg','png'))
       ->addValidator('MimeType',true,array('image/jpeg','image/png'))
       //->addValidator('ImageSize',true,array(0,0,340,480));
       //	->setMultiFile(3)
       ;
      $this->addElement($logo_picture_img);

      $view_picture_img = $this->createElement('file', 'view_picture_img', array(
        	'label'      => 'view_picture',
        	'filters'    => array('StringTrim'),
		)
		);
		$view_picture_img->addValidator('Count', true, 2)
       ->addValidator('Size', true, "3000KB")
       ->addValidator('Extension', true, array('jpg','png'))
       ->addValidator('MimeType',true,array('image/jpeg','image/png'))
       //->addValidator('ImageSize',true,array(0,0,340,480));
       //	->setMultiFile(3)
       ;
      $this->addElement($view_picture_img);

      $position_picture_img = $this->createElement('file', 'position_picture_img', array(
        	'label'      => 'position_picture',
        	'filters'    => array('StringTrim'),
		)
		);

		$position_picture_img->addValidator('Count', true, 2)
       ->addValidator('Size', true, "3000KB")
       ->addValidator('Extension', true, array('jpg','png'))
       ->addValidator('MimeType',true,array('image/jpeg','image/png'))
       //->addValidator('ImageSize',true,array(0,0,340,480));
       //	->setMultiFile(3)
       ;
      $this->addElement($position_picture_img);

  		$banner_picture_img = $this->createElement('file', 'banner_picture_img', array(
        	'label'      => 'banner_picture',
        	'filters'    => array('StringTrim'),
		)
		);

		$banner_picture_img->addValidator('Count', true, 2)
       ->addValidator('Size', true, "3000KB")
       ->addValidator('Extension', true, array('jpg','png'))
       ->addValidator('MimeType',true,array('image/jpeg','image/png'))
       //->addValidator('ImageSize',true,array(0,0,340,480));
       //	->setMultiFile(3)
       ;
      $this->addElement($banner_picture_img);

        $this->addElement('text', 'logo_picture', array(
        	'label'      => 'logo_picture',
        	'filters'    => array('StringTrim'),
        //	'validators' => array()
        	)
        );
        $this->addElement('text', 'view_picture', array(
        	'label'      => 'view_picture',
        	'filters'    => array('StringTrim'),
        //	'validators' => array()
        	)
        );
        $this->addElement('text', 'position_picture', array(
        	'label'      => 'position_picture',
        	'filters'    => array('StringTrim'),
        //	'validators' => array()
        	)
        );
        $this->addElement('text', 'banner_picture', array(
        	'label'      => 'banner_picture',
        	'filters'    => array('StringTrim'),
        //	'validators' => array()
        	)
        );


		$this->addDisplayGroup(
		array('id','show_id','commercial_id','governmental_id','attribute','name','name_short','name_brief',
			'english_name','length','county','township','zip_code',
			'address','phone','fax'
			), 'mainGroup',
			array(
                'disableLoadDefaultDecorators' => true,
                'decorators' => $this->standardGroupDecorator,
                'legend' => 'mainGroup'
                )
                );

		$this->addDisplayGroup(
		array('form_date','mark','area','montane','plottage','plottage_expand','floor_space'
			,'expense_capital','expense_ordinary','district','scale','email','website','hidden_id')
			,'subGroup',
			array(
				'disableLoadDefaultDecorators' => true,
            'decorators' => $this->standardGroupDecorator,
            'legend' => 'subGroup'
                )
		);

		$this->addDisplayGroup(
			array('logo_picture_img','view_picture_img','banner_picture_img','position_picture_img'),
			'fileGroup',
			array(
                'disableLoadDefaultDecorators' => true,
                'decorators' => $this->standardGroupDecorator,
                'legend' => 'fileGroup'
                )
			);
      //if ($this->_formState=='update')
         $this->_setValue();

	}


}
